<!DOCTYPE html>
<html>
<head lang="en">
	<meta charset="UTF-8">
<title>带关闭按钮的滚动广告</title>
<style type="text/css">
#main{ text-align:center;}
/*#float{
	position:absolute;
	left:30px;
	top:60px; 
	z-index:1;
	}
#close{
	position:absolute;
	top:60px;
	left:134px;
	z-index:2;
	cursor:hand;
}*/
</style>
</head>
<body>
<div id="close" style="position:absolute;top:60px;left:134px;z-index:2;cursor:hand;display: block;" onClick="adv_close()"><img src="../images/close.jpg"></div>
<div id="float" style="position:absolute;left:30px;top:60px; z-index:1;display: block;"><img src="../images/advpic.jpg"></div>
<div id="main"><img src="../images/contentpic.jpg"></div>
<script>
		var adverTop;
		var adverLeft;
		var adverTop2;
		var adverLeft2;
		var adverObj;
		var adverObj2;
	function inix(){		
		adverObj=document.getElementById("float");
		if(adverObj.currentStyle){
			adverTop=parseInt(adverObj.currentStyle.top);
			adverLeft=parseInt(adverObj.currentStyle.left);
		}else{
			adverTop=parseInt(document.defaultView.getComputedStyle(adverObj,null).top);
			adverLeft=parseInt(document.defaultView.getComputedStyle(adverObj,null).left);
		}
		adverObj2=document.getElementById("close");
		if(adverObj2.currentStyle){
			adverTop2=parseInt(adverObj2.currentStyle.top);
			adverLeft2=parseInt(adverObj2.currentStyle.left);
		}else{
			adverTop2=parseInt(document.defaultView.getComputedStyle(adverObj2,null).top);
			adverLeft2=parseInt(document.defaultView.getComputedStyle(adverObj2,null).left);
		}
		
	}
	function move(){
		var scrollTop=parseInt(document.documentElement.scrollTop||document.body.scrollTop);
		var scrollLeft=parseInt(document.documentElement.scrollLeft||document.body.scrollLeft);
		adverObj.style.top=adverTop+scrollTop+"px";
		adverObj.style.left=adverLeft+scrollLeft+"px";
		
		var scrollTop=parseInt(document.documentElement.scrollTop||document.body.scrollTop);
		var scrollLeft=parseInt(document.documentElement.scrollLeft||document.body.scrollLeft);
		adverObj2.style.top=adverTop2+scrollTop+"px";
		adverObj2.style.left=adverLeft2+scrollLeft+"px";
	}	
		window.onload=inix;
		window.onscroll=move;
	function adv_close(){
		document.getElementById("close").style.display="none";
		document.getElementById("float").style.display="none";
	}
</script>
</body>
</html>
